<template>
  <el-dialog title="订单详情" :visible.sync="dialogVisible" width="30%">
    <h3>预订信息：</h3>
    <p>项目：{{ detail.itemName }}</p>
    <p v-for="(item, index) in detail.orderInfoList" :key="index">
      {{ item.regionName }} {{ item.siteName }} {{ item.createDate }}
      {{ item.startTime }}-{{ item.endTime }} ￥{{ item.price }}
    </p>
    <h3>会员信息:</h3>
    <p>订单号：{{ detail.orderNumber }}</p>
    <p>会员名/姓名：{{ detail.memberName }} 会员等级：{{ detail.levelName }}</p>

    <p>会员ID：{{ detail.memberId }}</p>
    <p>手机号：{{ detail.phone }}</p>
    <h3>订单信息:</h3>
    <p>订单状态：{{ detail.orderStatus }}</p>
    <p>
      订单来源：{{
        detail.orderSource == 1
          ? "小程序"
          : detail.orderSource == 2
          ? "POS"
          : detail.orderSource == 3
          ? "后台"
          : "未知来源"
      }}
    </p>
    <p>支付方式：{{ detail.payType }}</p>
    <p>客户姓名:{{ detail.orderMemberName }}</p>
    <p>第三方订单号：{{ detail.outTradeNo }}</p>
    <p>操作人：{{ detail.sysUserName }}</p>
    <p>订单价格：￥{{ detail.orderAmount }}</p>
    <p>优惠：￥{{ detail.activityReduction }}</p>
    <p>健身红包：￥{{ detail.redPackedAmount }}</p>
    <p>实付：￥{{ detail.payAmount }}</p>
    <p>创建时间：{{ detail.createTime }}</p>
    <p>支付时间：{{ detail.createTime }}</p>
    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        size="small"
        @click="confirmOrder"
        v-if="detail.orderStatus == '待支付' && detail.payType != '礼品卡'"
        >确认收款</el-button
      >
      <el-button
        type="primary"
        size="small"
        @click="refund"
        v-if="detail.orderStatus == '已完成' && detail.payType != '礼品卡'"
        >退款</el-button
      >
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { orderDetail, settingBookGround, refund } from '@/config/api'
import { times, divide } from "@/utils/tools"

export default {
  data () {
    return {
      dialogVisible: false,
      detail: {}
    };
  },
  methods: {
    show (id) {
      this.getDeta(id)
      this.dialogVisible = true
    },
    getDeta (id) {
      orderDetail({ id }).then(res => {
        res.data.result.price = divide(res.data.result.price || 0, 100)
        res.data.result.orderAmount = divide(res.data.result.orderAmount || 0, 100)
        res.data.result.redPackedAmount = divide(res.data.result.redPackedAmount || 0, 100)
        res.data.result.activityReduction = divide(res.data.result.activityReduction || 0, 100)
        res.data.result.payAmount = divide(res.data.result.payAmount || 0, 100)
        res.data.result.orderInfoList.map(item => {
          item.price = divide(item.price, 100)
        })
        this.detail = res.data.result
      })
    },
    refund () {
      const sele = this
      this.$confirm('此操作将退款该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        refund({ orderId: this.detail.id, }).then(res => {
          if (res.data.status == 200) {
            this.$parent.getData()
            this.dialogVisible = false
            this.$message({
              type: 'success',
              message: '确认成功!'
            });
          }

        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    confirmOrder () {
      const sele = this
      this.$confirm('此操作将确认该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let ids = []
        let arr = []
        this.detail.orderInfoList.map(item => {
          if (item.gymSiteRecordId) {
            ids.push(item.gymSiteRecordId)
          }
          if (item.relevantRecordId != 0 && item.relevantRecordId != null) {
            arr.push(item.relevantRecordId)
          }
        })
        settingBookGround({ "operation": "1", gymSiteRecordList: ids, relevantRecordList: arr }).then(res => {
          if (res.data.status == 200) {
            this.$parent.getData()


            this.dialogVisible = false
            this.$message({
              type: 'success',
              message: '确认成功!'
            });
          }

        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>
<style scoped>
p {
  margin: 15px 0;
}
</style>